package mill;


import java.io.Serializable;
import java.util.*;

import mill.components.Generator;
import mill.components.MillComponent;
import mill.measurePoints.MeasurePoint;

/**
 * @author Daniel
 *
 */
public class ConcreteMill implements IMill , Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//members
	private final int m_serialNumber;
	private int m_height, m_wingSpan, m_powerOutput;
	private ProductionStatus m_status;
	private MillType m_type;
	private List<MeasurePoint> m_measurePoints;
	private List<MillComponent> m_components;


	public ConcreteMill(int height, int serialNumber, MillType type, int span) {
		super();

		m_height = height;
		m_serialNumber = serialNumber;
		m_type = type;
		m_wingSpan = span;

		m_measurePoints = new ArrayList<MeasurePoint>();
		m_components = new ArrayList<MillComponent>();
		m_powerOutput = 0;
		m_status = ProductionStatus.Stop;
	}

	@Override
	public List<MillComponent> getComponents() {
		return m_components;
	}

	@Override
	public int getHeight() {
		return m_height;
	}

	@Override
	public List<MeasurePoint> getMeasurePoints() {
		return m_measurePoints;
	}

	@Override
	public int getPowerOutput() {	

		if(m_status == ProductionStatus.Pause || m_status == ProductionStatus.Stop)
			return 0;
		
		for(MillComponent mc : m_components)
		{
			if(mc instanceof Generator){
				m_powerOutput = (int)Math.round(((Generator)mc).get_powerOutput());
				break;
			}
		}
		
		return m_powerOutput;
	}

	@Override
	public void setStatus(ProductionStatus status) {
		m_status = status;
	}
	
	@Override
	public int getSerialNumber() {
		return m_serialNumber;
	}

	@Override
	public ProductionStatus getStatus() {
		return m_status;
	}

	@Override
	public MillType getType() {
		return m_type;
	}

	@Override
	public int getWingSpan() {
		return m_wingSpan;
	}

	@Override
	public boolean addComponents(MillComponent component) {
		return m_components.add(component);

	}

	@Override
	public boolean addMeasurePoint(MeasurePoint point) {
		return m_measurePoints.add(point);

	}

	@Override
	public boolean removeComponents(MillComponent component) {
		return m_components.remove(component);

	}

	@Override
	public boolean removeMeasurePoint(MeasurePoint point) {
		return m_measurePoints.remove(point);

	}

	@Override
	public boolean pauseMill() {
		m_status = ProductionStatus.Pause;
		return true;
	}

	@Override
	public boolean startMill() {
		m_status = ProductionStatus.Start;
		return true;
	}

	@Override
	public boolean stopMill() {
		m_status = ProductionStatus.Stop;
		return true;
	}


	@Override
	public String toString()
	{
		return "Mill serial number: " + m_serialNumber;
	}
}
